<template>
	<view class="wrap">
		<view class="top">
			<view class="item">
				<view class="left">联 系 人</view>
				<input type="text" v-model="username" placeholder-class="line" placeholder="请填写收货人姓名" />
			</view>
			<view class="item">
				<view class="left">联系方式</view>
				<input type="text" v-model="telphone" placeholder-class="line" placeholder="请填写收货人手机号" />
			</view>
			<view class="item" @tap="show = true">
				<view class="left">所 在 地</view>
				<image src="../static/address_tb1.png" class="img_box"></image>
				<input disabled type="text" v-model="region" placeholder-class="line" placeholder="省市区县、乡镇等" />
			</view>
			<view class="item" style="border: 0;">
				<view class="left">详细地址</view>
				<input type="text" v-model="detail" placeholder-class="line" placeholder="请输入详细地址" />
			</view>
		</view>
		<view class="bottom">
			<view class="default" @click="setDefault">
				<image v-if="state==1" src="../static/b2.png"></image>
				<image v-if="state==0" src="../static/b1.png"></image>
				<view class="left">
					<view class="set">设置默认地址</view>
				</view>
			</view>
		</view>
		<u-picker mode="region" ref="uPicker" @confirm="showRegionPicker" v-model="show" />
		<view class="view">
			<u-button :ripple="true" type="primary"  @click="address()" class="u-button">确认添加</u-button>
		</view>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				show: false,
				username: "",
				telphone: "",
				region: "",
				detail: "",
				state: 1
			};
		},
		onLoad() {
			than = this;
		},
		methods: {
			setDefault() {
				than.state = than.state == 1 ? 0 : 1
			},
			showRegionPicker(e) {
				than.region = e.province.label + " " + e.city.label + " " + e.area.label
			},
			address() {
				if (!!!than.username) {
					than.toast("未填写收货人")
					return false
				}
				if (!!!than.telphone) {
					than.toast("未填写收货电话")
					return false
				}
				if (!!!than.region) {
					than.toast("未选择所在地区")
					return false
				}
				if (!!!than.detail) {
					than.toast("未填写详细地址")
					return false
				}
				than.post("api/address/addPost", {
					username: than.username,
					telphone: than.telphone,
					region: than.region,
					detail: than.detail,
					state: than.state
				}, function(data) {
					than.toast(data)
					setTimeout(function() {
						uni.navigateBack()
					}, 1500);
				})
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	/deep/ .line {
		color: $u-light-color;
		font-size: 28rpx;
	}

	.view {
		position: fixed;
		width: 100%;
		bottom: 31rpx;

		.u-button {
			// height: 80rpx;
			// width: 314rpx;
			color: #ffffff;
			// background: #FEC31D;
			// box-shadow: 0px 6rpx 8rpx 0px rgba(170, 170, 170, 0.16);
			// border-radius: 40rpx;
			width: 245rpx;
			height: 74rpx;
			background: #FB683D;
			border-radius: 20rpx;
		}
	}

	.wrap {
		padding-top: 36rpx;

		.top {
			background-color: #ffffff;
			padding: 0 22rpx;
			border-radius: 20rpx;
			margin: 0 36rpx;

			.item {
				display: flex;
				font-size: 32rpx;
				line-height: 100rpx;
				align-items: center;
				border-bottom: solid 2rpx $u-border-color;
                .img_box{
					width:30rpx;height:41rpx;margin-right: 10rpx;
				}
				.left {
					width: 180rpx;
				}

				input {
					text-align: left;
				}
			}

			.address {
				padding: 20rpx 0;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}
			}

			.site-clipboard {
				padding-right: 40rpx;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}

				.clipboard {
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: $u-tips-color;
					height: 80rpx;

					.icon {
						margin-top: 6rpx;
						margin-left: 10rpx;
					}
				}
			}
		}

		.bottom {
			margin: 20rpx 36rpx;
			height: 122rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding-right: 0;
			background-color: #ffffff;
			font-size: 28rpx;

			.tag {
				display: flex;

				.left {
					width: 160rpx;
				}

				.right {
					display: flex;
					flex-wrap: wrap;

					.tags {
						width: 140rpx;
						padding: 16rpx 8rpx;
						border: solid 2rpx $u-border-color;
						text-align: center;
						border-radius: 50rpx;
						margin: 0 10rpx 20rpx;
						display: flex;
						font-size: 28rpx;
						align-items: center;
						justify-content: center;
						color: $u-content-color;
						line-height: 1;
					}

					.plus {
						//padding: 10rpx 0;
					}
				}
			}

			.default {
				margin-top: 50rpx;
				display: flex;
				justify-content: space-between;
				height: 100%;
				padding: 0 20rpx;
				align-items: center;

				image {
					width: 36rpx;
					height: 36rpx;
				}

				.left {
					margin-left: 15rpx;
					margin-right: auto;
				}
			}
		}
	}
</style>
